import React, {Component} from 'react';
import {Card, Table, Button, Popconfirm, message} from 'antd'

class List extends Component {
    constructor(props) {
        super(props)
    };

    render() {
        const columns = [
            {
                title: '序号',
                key: 'id',
                width: 80,
                align: 'center',
                render: (txt, item, index) => index + 1
            },
            {
                title: '名字',
                dataIndex: 'name'
            },
            {
                title: '价格',
                dataIndex: 'price'
            },
            {
                title: '操作',
                render: (item, index) => {
                    return (
                        <div>
                            <Button type="primary" size="small" onClick={() => {
                                alert(item.name)
                            }}>修改</Button>
                            <Popconfirm title="是否确认删除?" onConfirm={() => message.success('删除成功!')}
                                        onCancel={() => message.error('取消删除!')}>
                                <Button style={{marginLeft: '10px'}} type="danger" size="small">删除</Button>
                            </Popconfirm>
                        </div>
                    )
                }
            }
        ];
        const dataSource = [
            {
                id: 1,
                name: '煎饼果子',
                price: 6
            },
            {
                id: 2,
                name: '鸡蛋灌饼',
                price: 10
            },
            {
                id: 3,
                name: '打卤馕',
                price: 198
            }
        ];
        return (
            <Card title="商品列表" extra={<Button type="priamry" size="small"
            onClick={()=>{this.props.history.push('/admin/products/edit')}}
            >新增</Button>}>
                <Table columns={columns} bordered dataSource={dataSource}></Table>

            </Card>
        );
    }
}

export default List;
